package com.dcbeida.activity.salsesdedail;

import android.app.Activity;
import android.content.DialogInterface;
import android.support.annotation.Nullable;

import com.dcbeida.bean.ReturnDetail;
import com.dcbeida.callback.DialogCallback;
import com.dcbeida.model.ModelUtils;
import com.dcbeida.utils.JsonGet;

import java.lang.reflect.Type;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by 150410 on 2017/10/19.
 */

public class ReturnDetailPresenter implements ReturnDetailContract.Present {

    private final ModelUtils model;
    private ReturnDetailContract.View view;
    private Activity act;

    public ReturnDetailPresenter(ReturnDetailContract.View view, Activity act) {
        this.view = view;
        model = ModelUtils.newInstance();
        this.act = act;
    }


    @Override
    public void start() {

    }


    //取消dialog 取消请求
    DialogInterface.OnCancelListener lis = new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            model.getCancel();
        }
    };


    @Override
    public void getReturnDetailInfo(String uid, String refundid) {
        JsonGet jg = new JsonGet().putopt("uid", uid)
                .putopt("refundid", refundid);
        String json = jg.tostring();

        model.getDate("getrefunddetail", json, new ReturnDetailPresenter.GetListCallBack(act, ReturnDetail.class, lis));
    }

    public class GetListCallBack<T> extends DialogCallback<T> {
        public GetListCallBack(Activity activity, Type type, DialogInterface.OnCancelListener lis) {
            super(activity, type, lis);
        }

        @Override
        public void onResponse(T data) {
            if (data != null) {
                view.showReturnDetailList((ReturnDetail) data);
            }
        }

        public void onError(boolean isFromCache, Call call, @Nullable Response response, @Nullable Exception e) {
            super.onError(call, response, e);
            view.showTip("数据未请求成功,请检查网络...");
        }
    }

}
